package cn.yj.common.monitor;

import cn.yj.common.interfaces.AbstractPay;
import cn.yj.common.service.PayRefundSuccessNotifyHandler;
import cn.yj.common.service.PaySuccessNotifyHandler;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;

import javax.annotation.Resource;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;

/**
 * @author 永健
 * @since 2022-02-21 10:03
 */
public abstract class AbstractPayOrderMonitor implements IPayOrderMonitor {

    @Resource
    protected PaySuccessNotifyHandler notifyHandler;

    @Resource
    protected PayRefundSuccessNotifyHandler notifyRefundHandler;

    private static final int corePoolSize;

    protected static ScheduledExecutorService scheduledExecutorService;

    static {
        corePoolSize = Runtime.getRuntime().availableProcessors() * 2;

        scheduledExecutorService = new ScheduledThreadPoolExecutor(corePoolSize,
                new BasicThreadFactory.Builder().namingPattern("schedule" + "-pool-%d").daemon(true).build(), (
                r, executor) -> {

        }) {
            @Override
            protected void afterExecute(Runnable r, Throwable t) {
                super.afterExecute(r, t);
            }
        };
    }
}
